
package swa.e_store.userInterface;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * The GUIListener class represents the listener used by the LogicUI class
 * to determine the button clicked. Depending on the button clicked, the
 * logic-method responsible will be called.
 *
 * @author Stefan Schibig (stefan.schibig@stud.hslu.ch)
 */
public class GUIListener implements ActionListener{
    
    private LogicUI logik;

    public GUIListener(LogicUI logik){

        this.logik = logik;

    }

    /**
     * The actionPerfomed method will be called if a button of the GraphicalUI
     * is clicked. Depending on the button clicked, this method calls the
     * right method responsible of the LogicUI class.
     *
     * @param e the ActionEvent what happened.
     */
    public void actionPerformed(ActionEvent e) {
        // String actionCommand
        String actionCommand = e.getActionCommand();

        /**
         * "Methode" zum manuellen Auslesen der Hashwerte. Wird
         * wird für die Switch-Schlaufe gebraucht.
         */

        System.out.println(actionCommand + ", Hash " + actionCommand.hashCode());


        /**
         * Menu "File"
         * ------------
         * Show Article Table, Hash 957978657
         * Order from Central System, Hash 1421553342
         * Show Articles by Offer, Hash 539088211
         * Take Purchase Order, Hash -1328524280
         * Show Offers, Hash 1085762586
         * Show Stock, Hash 1286070323
         * Show Shop Report, Hash -698774245
         * Quit, Hash 2528879
         */

        switch(actionCommand.hashCode()){

            /**
             * Hashcases for menu Datei
             */

            // Show Article Table
            case 957978657:    logik.actionShowArticleTable();
                                break;
            // Order from Central System
            case 1421553342:    logik.actionCISOrder();
                                break;

            // Show Articles by Offer
            case 539088211:     logik.actionShowArticleByOffer();
                                break;

            // Take Purchase Order
            case -1328524280:     logik.actionPurchaseOrder();
                                break;

            // Show Offers
            case 1085762586:     logik.actionShowOffers();
                                break;

            // Show Stock
            case 1286070323:     logik.actionShowStock();
                                break;
                
            // Show Shop Report
            case -698774245:    logik.actionShopReport();
                                break;

            // Quit
            case 2528879:     logik.actionQuit();

        }

    }

}
